package com.ea.report.controller;

import com.ea.common.log.LogAnnotation;
import com.ea.common.report.pojo.param.*;
import com.ea.common.report.pojo.vo.*;
import com.ea.common.result.Result;
import com.ea.common.utils.ParamUtil;
import com.ea.report.service.ReportService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Resource
    ReportService reportService;

    @Transactional
    @PostMapping("/getUserReportVoByUserId")
    @LogAnnotation(module = "ReportController", operation = "获得用户的报告")
    public Result<UserDetailVo> getUserReportVoByUserId(@RequestBody GetUserReportVoParam getUserReportVoParam) {
        UserDetailVo result = reportService.getUserReportVoByUserId(
                ParamUtil.parseId(getUserReportVoParam.getUserId()));
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/uploadVideo")
    @LogAnnotation(module = "ReportController", operation = "分析视频")
    public Result<Long> uploadVideo(@RequestParam("md5") String md5,
                                    @RequestParam("userId") String userId,
                                    @RequestParam("companyId") String companyId,
                                    @RequestParam("type") Integer type) {
        Long userIdLong = null;
        if (userId != null) {
            userIdLong = ParamUtil.parseId(userId);
        }
        Long result = reportService.uploadVideo(
                md5,
                userIdLong,
                ParamUtil.parseId(companyId),
                type
        );
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/uploadPhoto")
    @LogAnnotation(module = "ReportController", operation = "上传注册照片")
    public Result uploadPhoto(@RequestParam("md5") String md5,
                              @RequestParam("userId") String userId,
                              @RequestParam("name") String name) {
        reportService.uploadPhoto(
                md5,
                ParamUtil.parseId(userId),
                name
        );
        return Result.success(null);
    }

    @Transactional
    @PostMapping("/uploadPhotoTemp")
    public Result uploadPhotoTemp(@RequestParam("md5") String md5,
                              @RequestParam("userId") String userId,
                              @RequestParam("name") String name) {
        reportService.uploadPhotoTemp(
                md5,
                ParamUtil.parseId(userId),
                name
        );
        return Result.success(null);
    }

    @Transactional
    @PostMapping("/getReportSimpleInfoVoListByUserId")
    @LogAnnotation(module = "ReportController", operation = "获得指定人员的所有报告")
    public Result<ReportSimpleInfoListVo> getReportSimpleInfoVoListByUserId(
            @RequestBody @Valid GetReportSimpleInfoVoListParam getReportSimpleInfoVoListParam) {
        ReportSimpleInfoListVo result = reportService.getReportSimpleInfoVoListByUserId(
                ParamUtil.parseId(getReportSimpleInfoVoListParam.getUserId()),
                getReportSimpleInfoVoListParam.getName(),
                getReportSimpleInfoVoListParam.getCompanyName(),
                getReportSimpleInfoVoListParam.getDeptName(),
                getReportSimpleInfoVoListParam.getPositionName(),
                getReportSimpleInfoVoListParam.getWarningTypeList(),
                getReportSimpleInfoVoListParam.getPage(),
                getReportSimpleInfoVoListParam.getPageSize()
        );
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/getReportList")
    @LogAnnotation(module = "ReportController", operation = "获得报告列表")
    public Result<ReportSimpleInfoListVo> getReportList(
            @RequestBody @Valid GetReportListParam getReportListParam
            ) {
        ReportSimpleInfoListVo result = reportService.getReportList(
                getReportListParam.getCompanyIdList(),
                getReportListParam.getDeptIdList(),
                getReportListParam.getPositionIdList(),
                getReportListParam.getUserIdList(),
                getReportListParam.getWarningTypeList(),
                getReportListParam.getStatusList(),
                getReportListParam.getName(),
                getReportListParam.getPostStartDate(),
                getReportListParam.getPostEndDate(),
                getReportListParam.getReceiveStartDate(),
                getReportListParam.getReceiveEndDate(),
                getReportListParam.getEmoAnalyStartDate(),
                getReportListParam.getEmoAnalyEndDate(),
                getReportListParam.getHeartRateStartDate(),
                getReportListParam.getHeartRateEndDate(),
                getReportListParam.getPage(),
                getReportListParam.getPageSize()
        );
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/getReportListNew")
    @LogAnnotation(module = "ReportController", operation = "获得报告列表")
    public Result<ReportSimpleInfoListVo> getReportListNew(
            @RequestBody GetReportListNewParam getReportListNewParam
            ) {
        ReportSimpleInfoListVo result = reportService.getReportList(
                getReportListNewParam.getCompanyIdList(),
                getReportListNewParam.getDepartmentIdList(),
               getReportListNewParam.getPositionIdList(),
                getReportListNewParam.getUserIdList(),
                getReportListNewParam.getWarningTypeList(),
                getReportListNewParam.getStatusList(),
                getReportListNewParam.getName(),
               getReportListNewParam.getPostStartDate(),
                getReportListNewParam.getPostEndDate(),
                getReportListNewParam.getReceiveStartDate(),
                getReportListNewParam.getReceiveEndDate(),
                getReportListNewParam.getEmoAnalyStartDate(),
                getReportListNewParam.getEmoAnalyEndDate(),
                getReportListNewParam.getHeartRateStartDate(),
                getReportListNewParam.getHeartRateEndDate(),
                getReportListNewParam.getPage(),
                getReportListNewParam.getPageSize()
        );
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/getReportDetail")
    @LogAnnotation(module = "ReportController", operation = "获得报告详情")
    public Result<ReportDetailInfoVo> getReportDetail(
            @RequestParam("reportId") String reportId
    ) {
        ReportDetailInfoVo result = reportService.getReportDetail(
                ParamUtil.parseId(reportId)
        );
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/getCompanyIdByReportId")
    @LogAnnotation(module = "ReportController", operation = "获得报告的公司id")
    public Result<String> getCompanyIdByReportId(
            @RequestParam("reportId") String reportId
    ) {
        String result = reportService.getCompanyIdByReportId(
                ParamUtil.parseId(reportId)
        );
        return Result.success(result);
    }

    @Transactional
    @PostMapping("/getWarningInfoVo")
    @LogAnnotation(module = "ReportController", operation = "获得预警人数信息")
    public Result<GetWarningInfoVo> getWarningInfoVo(
            @RequestBody GetWarningInfoLongParam getWarningInfoLongParam
    ) {
        GetWarningInfoVo result = reportService.getWarningInfoVo(
                getWarningInfoLongParam.getCompanyIdList(),
                getWarningInfoLongParam.getDepartmentIdList(),
                getWarningInfoLongParam.getPositionIdList(),
                getWarningInfoLongParam.getPropertiesIdList(),
                getWarningInfoLongParam.getName(),
                getWarningInfoLongParam.getWarningTypeList(),
                getWarningInfoLongParam.getPage(),
                getWarningInfoLongParam.getPageSize()
        );
        return Result.success(result);
    }


    @PostMapping("/getStatsReport")
    Result<StatsReportVo> getStatsReport(
            @RequestBody @Valid GetStatsReportVoParam getStatsReportParam
    ) {
        StatsReportVo result = reportService.getStatsReport(
                getStatsReportParam.getCompanyIdList(),
                getStatsReportParam.getDeptIdList(),
                getStatsReportParam.getTotalCount(),
                getStatsReportParam.getStartDate(),
                getStatsReportParam.getEndDate()
        );
        return Result.success(result);
    }


    @PostMapping("/getDashboardVo")
    Result<DashboardVo> getDashboardVo(
            @RequestBody @Valid GetDashboardVoParam getDashboardVoParam
    ) {
        DashboardVo result = reportService.getDashboardVo(
                getDashboardVoParam.getCompanyIdList(),
                getDashboardVoParam.getDeptIdList(),
                getDashboardVoParam.getTotalCount(),
                getDashboardVoParam.getTotalCountFemale(),
                getDashboardVoParam.getTotalCountMale(),
                getDashboardVoParam.getStartDate(),
                getDashboardVoParam.getEndDate()
        );
        return Result.success(result);
    }

    @PostMapping("/getPropertiesList")
    Result<GetPropertiesListVo> getPropertiesList(){
        GetPropertiesListVo result=reportService.getPropertiesList();
        return Result.success(result);
    }



    @PostMapping("/deleteUserFace")
    Result deleteUserFace(@RequestParam("userId") String userId) {
        reportService.deleteUserFace(ParamUtil.parseId(userId));
        return Result.success(null);
    }

    @PostMapping("/updateUserInfo")
    Result updateUserInfo(
            @RequestParam("userId") Long userId,
            @RequestParam("companyId") Long companyId
    ) {
        reportService.updateUserInfo(
                userId,
                companyId
        );
        return Result.success(null);
    }

    @PostMapping("/getReportInfo")
    @LogAnnotation(module = "ReportController", operation = "获得报告详情")
    public Result<ReportDetailInfoVo> getReportInfo(
            @RequestParam("userId") String userId,
            @RequestParam("md5") String md5
    ) {
        ReportDetailInfoVo result = reportService.getReportInfoByMd5(ParamUtil.parseId(userId),md5);
        return Result.success(result);
    }

}
